import { formatReportInfo } from '@/utils/format-report-info';
import { ApiTrack } from '../core';
import { ApiTrackPlugin } from '../types';
import { Collector } from 'byted-tea-sdk';

export const teaReporter: ApiTrackPlugin<ApiTrack, unknown> = () => {
  const reporter = new Collector('reporter');
  reporter.init({
    app_id: 518168,
    channel: 'cn',
    enable_stay_duration: false,
    disable_heartbeat: true,
    disable_route_report: true,
    disable_auto_pv: true,
    log: true,
    spa: false, // 切换path不重新上报pv 不是应该true吗
  });

  reporter.start();

  return (resultInfos) => {
    if (!resultInfos) return;
    const categories = formatReportInfo(resultInfos);
    reporter.event('effect_recycl', { type: resultInfos?.type, ...categories });
  };
};
